package org.cskj.demo.demo.controller;

import org.cskj.demo.pojo.User;
import org.cskj.demo.service.imp.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@ResponseBody
@RequestMapping("/user")
public class UserController {
    private final double size=8;
    @Autowired
    private UserService userService;
    @RequestMapping("/all")
    public List<User> getall(int page){

        int count =userService.count();
        double pageMax=Math.ceil(count/size);

        //计算page是否有效
        page=page>(int)(pageMax)?(int)(pageMax):page;
        //获取数据
        List<User> users1 = userService.getall(page, (int) size);
        return users1;
    }
}
